import { createRouter, createWebHashHistory } from 'vue-router';

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/:pathMatch(.*)',
      redirect: '/task',
    },
    {
      path: '/',
      redirect: '/task'
    },
    {
      path: '/sign-in',
      name: 'sign-in',
      component: () => import('@/views/sign-in/index.vue'),
    },
    {
      path: '/',
      component: () => import('@/views/primary/index.vue'),
      children: [
        {
          path: 'task',
          component: () => import('@/views/all-task/index.vue'),
          meta: {
            title: '全部任务',
          },
        },
        {
          path: 'task-edit',
          component: () => import('@/views/task-edit/index.vue'),
          props: route => route.query,
          meta: {
            back: '/task',
          },
        },
        {
          path: 'task-assign-11',
          component: () => import('@/views/task-assign/obj-detn.vue'),
          props: route => route.query,
          meta: {
            title: '分配任务',
            back: '/task',
          },
        },
        {
          path: 'task-assign-12',
          component: () => import('@/views/task-assign/video-action.vue'),
          props: route => route.query,
          meta: {
            title: '分配任务',
            back: '/task',
          },
        },
        {
          path: 'task-assign-23',
          component: () => import('@/views/task-assign/seq-label.vue'),
          props: route => route.query,
          meta: {
            title: '分配任务',
            back: '/task',
          },
        },
        {
          path: 'task-detail',
          component: () => import('@/views/task-detail/index.vue'),
          props: route => route.query,
          meta: {
            title: '任务详情',
            back: '/task',
          },
        },
        {
          path: 'obj-detn',
          component: () => import('@/views/obj-detn/index.vue'),
          props: route => route.query,
          meta: {
            headerVisible: false
          },
        },
        {
          path: 'seq-label',
          component: () => import('@/views/seq-label/index.vue'),
          meta: {
            headerVisible: false
          },
        },
        {
          path: 'text-classification',
          component: () => import('@/views/text-classification/index.vue'),
          meta: {
            headerVisible: false
          },
        },
        {
          path: 'video-action',
          component: () => import('@/views/video-action/index.vue'),
          props: route => route.query,
          meta: {
            headerVisible: false
          },
        },
        {
          path: 'menu',
          component: () => import('@/views/menu-manage/index.vue'),
          meta: {
            title: '菜单管理',
          },
        },
        {
          path: 'func',
          component: () => import('@/views/func-manage/index.vue'),
          props: route => route.query,
          meta: {
            title: '功能列表',
            back: '/menu',
          },
        },
        {
          path: 'user',
          component: () => import('@/views/user-manage/index.vue'),
          meta: {
            title: '用户管理',
          },
        },
        {
          path: 'org',
          component: () => import('@/views/org-manage/index.vue'),
          meta: {
            title: '机构管理',
          },
        },
        {
          path: 'role',
          component: () => import('@/views/role-manage/index.vue'),
          meta: {
            title: '角色管理',
          },
        },
        {
          path: 'group',
          component: () => import('@/views/group-manage/index.vue'),
          meta: {
            title: '分组管理',
          },
        },
      ],
    },
  ],
});

router.beforeEach((to, from, next) => {
  if ('/task-edit' == to.path) {
    to.meta.title = to.query.id ? '编辑任务' : '新建任务';
  }

  next();
});

export default router;
